package com.sugon.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevMainBaseDao;
import com.sugon.dao.DevPlanGcRecordDao;
import com.sugon.entity.DevMainBaseEntity;
import com.sugon.entity.DevPlanGcRecordEntity;
import com.sugon.service.DevPlanGcRecordService;
import com.sugon.service.SysDeptService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * ${comments}Service实现类
 *
 * @author sugon
 * @date 2020-03-11 10:30:43
 */
@Service("devPlanGcRecordService")
public class DevPlanGcRecordServiceImpl implements DevPlanGcRecordService {
    @Autowired
    private DevPlanGcRecordDao devPlanGcRecordDao;
    @Autowired
    private DevMainBaseDao devMainBaseDao;
    @Autowired
    private SysDeptService sysDeptService;

    /**
     * @param id 主键
     * @return
     */
    @Override
    public DevPlanGcRecordEntity queryObject(String id) {
        return devPlanGcRecordDao.queryObject(id);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public List<DevPlanGcRecordEntity> queryList(Map<String, Object> map) {
        //判断当前人员是否是维修人员
        String deptId = ShiroUtils.getUserEntity().getDeptId();
        Integer leader = ShiroUtils.getUserEntity().getLeader();
        String type = sysDeptService.getDeptTypeById(deptId);
        if ("DT_SBWXZ".equals(type)) {
            if (1 != leader) {
                map.put("EXECUTOR", ShiroUtils.getUserId());
            }
        }
        return devPlanGcRecordDao.queryList(map);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        //判断当前人员是否是维修人员
        return devPlanGcRecordDao.queryTotal(map);
    }

    /**
     * @param devPlanGcRecord 实体
     * @return
     */
    @Override
    public int save(DevPlanGcRecordEntity devPlanGcRecord) {
        devPlanGcRecord.setId(RandomUtil.randomString(32));
        devPlanGcRecord.setAuthor(ShiroUtils.getUserId());
        devPlanGcRecord.setIsShowT(1);
        devPlanGcRecord.setCheckFlag(0);
        return devPlanGcRecordDao.save(devPlanGcRecord);
    }

    /**
     * @param devPlanGcRecord 实体
     * @return
     */
    @Override
    public int update(DevPlanGcRecordEntity devPlanGcRecord) {
        return devPlanGcRecordDao.update(devPlanGcRecord);
    }

    /**
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devPlanGcRecordDao.delete(id);
    }

    /**
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devPlanGcRecordDao.deleteBatch(ids);
    }

    /**
     * @param devPlanGcRecord
     * @return
     */
    @Override
    public int assgin(DevPlanGcRecordEntity devPlanGcRecord) {
        return devPlanGcRecordDao.assgin(devPlanGcRecord);
    }

    /**
     * @param ids
     * @return
     */
    @Override
    public int batchEnd(String[] ids) {
        int flag = 0;
        if (ids.length > 0) {
            for (String id : ids) {
                DevPlanGcRecordEntity dgc = devPlanGcRecordDao.queryObject(id);
                dgc.setCheckFlag(1);
                devPlanGcRecordDao.update(dgc);
            }

        }
        return flag;
    }

    /**
     * @param idsStr
     * @return
     */
    @Override
    public int batchEndApi(String idsStr) {
        String[] ids = idsStr.split(",");
        int flag = 0;
        if (ids.length > 0) {
            for (String id : ids) {
                DevPlanGcRecordEntity dgc = devPlanGcRecordDao.queryObject(id);
                dgc.setCheckFlag(1);
                devPlanGcRecordDao.update(dgc);
            }
        }
        return flag;
    }

    /**
     * @param map
     * @return
     */
    @Override
    public List<DevPlanGcRecordEntity> infoList(Map<String, String> map) {
        return devPlanGcRecordDao.infoList(map);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public List<DevMainBaseEntity> queryList2(Map<String, Object> map) {
        return devMainBaseDao.getBaseInfoPage(map);
    }

    /**
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal2(Map<String, Object> map) {
        return devMainBaseDao.getBaseInfoTotal(map);
    }

}
